package Thread;

public class ThreadDemo6 {
    public static void main(String[] args) {
        Thread thread = new Thread(()->{
            while(!Thread.currentThread().isInterrupted()){
                System.out.println("hello boy");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        thread.start();
        for (int i = 0; i < 3; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        thread.interrupt();
    }
    public static void main1(String[] args) {
        Thread thread=new Thread(()->{
            while(!Thread.currentThread().isInterrupted()){  //Thread.currentThread这个是线程的引用对象，

                System.out.println("hello boy");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        thread.start();

        try {
            System.out.println("hello main");
            for(int i=0;i<3;i++) {
                Thread.sleep(1000);
            }

        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        thread.interrupt();
    }
}
